package com.zhitan.netty.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 硬件故障枚举（交流桩自定义）
 **/
@Getter
@AllArgsConstructor
public enum DeviceErrorEnum {
    /**
     * 硬件故障
     */
    UNKNOWN(-1, "未知错误"),
    E0(0, "LN反接"),
    E1(1, "急停开入"),
    E2(2, "漏电"),
    E3(3, "过压"),
    E4(4, "欠压"),
    E5(5, "过流"),
    E6(6, "桩过温"),
    E7(7, "枪过温"),
    E8(8, "地线未接"),
    E9(9, "继电器粘连"),
    E10(10, "保留"),
    E11(11, "CP错误"),
    E12(12, "桩温传错误"),
    E13(13, "枪温传错误"),
    E14(14, "保留"),
    E15(15, "保留"),
    ;

    private final int code;
    private final String message;

    /**
     * 根据code获取枚举
     */
    public static DeviceErrorEnum getByCode(int code) {
        for (DeviceErrorEnum value : DeviceErrorEnum.values()) {
            if (value.getCode() == code) {
                return value;
            }
        }
        return UNKNOWN;
    }
}
